class AjaxServe {
	constructor(props) {
		this.props = props;
		this.url = 'http://192.168.214.2:3000/';
		let obj = {};
		this.props.forEach((e) => { obj[e.name] = this.getMethodFn(e); });
		return obj;
	}

	getMethodFn(e){
	    var _self = this;
	    let ojb = {
	        'get'	: e => this.doGet(e),
	        'post'	: e => this.doPost(e),
	    }
	    return ojb[e.methed](e);
	}
	doPost(data){
	    let _self = this;
	    return function(param){
	        return fetch(
	        	_self.url + data.url,
	        	{method:'POST',headers:{'Content-Type':'application/json',},
	        	body:JSON.stringify(param),}
	        ).then((response) => response.json())
	    }
	}

	doGet(data){
		var _self = this; 
	    return function(param){
	    	let temp = '';
	    	for(let key in param){ temp = key + '=' + param[key]; }
	    	return fetch(_self.url + data.url + "?" + temp).then((response) => response.json())
	    }   
		
	}
}
export{AjaxServe}